import { AES, enc } from "crypto-ts";
const SECRET_KEY = "pinia持久化密钥";

// 自定义序列化器
const encryptedSerializer = {
  serialize: (value: any) => {
    const jsonString = JSON.stringify(value);
    const encrypted = AES.encrypt(jsonString, SECRET_KEY).toString();
    return encrypted;
  },
  deserialize: (value: string) => {
    const bytes = AES.decrypt(value, SECRET_KEY);
    const decrypted = bytes.toString(enc.Utf8);
    return JSON.parse(decrypted);
  },
};

export { encryptedSerializer };
